<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/4/13
  Time: 17:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <meta name="renderer" content="webkit">
    <title></title>

    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/pintuer.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/admin.css">
    <script src="${pageContext.request.contextPath}/js/jquery.js"></script>
    <script src="${pageContext.request.contextPath}/js/pintuer.js"></script>
    <script type=“text/javascript” src="${pageContext.request.contextPath}/js/jquery-1.11.3.min.js"></script>
    <script type=“text/javascript” src="${pageContext.request.contextPath}/js/json2.js"></script>
    <script src="${pageContext.request.contextPath}/js/echarts.min.js"></script>
    <script src="${pageContext.request.contextPath}/js/json2.js"></script>
</head>
<body>

<form method="post" action="">
    <div class="panel admin-panel">
        <div class="panel-head"><strong class="icon-reorder">本月考勤</strong></div>
        <div class="padding border-bottom"><%--value="<fmt:formatDate value="${date}" dateStyle="medium" pattern="yyyy--MM" />"--%>
            <input type="month"  id="month" onchange="findByMonth()">
            <input type="hidden" value="${param.userId}" id="user">
            <input type="hidden" value="${date}" id="datemonth">
        </div>
        <table class="table table-hover text-center">
            <tr>
                <th width="120">编号</th>
                <th>用户名</th>
                <th>日期</th>
                <th>上班时间</th>
                <th>下班时间</th>
                <th>是否迟到</th>
                <th>是否早退</th>
                <th>操作</th>
            </tr>
            <c:forEach items="${attendancelist}" var="attendancelist" varStatus="a">
                <tr>
                    <td> ${a.count}</td>
                    <td> ${attendancelist.user.userName}</td>
                    <td><fmt:formatDate value="${attendancelist.brushDate}" dateStyle="medium" pattern="yyyy-MM-dd" /></td>
                    <td> <fmt:formatDate value="${attendancelist.attendanceTime.mintime}" dateStyle="medium" pattern="HH:mm:ss" var="mintime" />${mintime}</td>
                    <td> <fmt:formatDate value="${attendancelist.attendanceTime.maxtime}" dateStyle="medium" pattern="HH:mm:ss" var="maxtime" />${maxtime}</td>
                    <td>
                        <c:if test="${mintime>'08:00:00'}">
                            <a class="button border-red" href="javascript:void(0)"
                            >迟到</a>
                        </c:if>
                    </td>
                    <td>
                        <c:if test="${maxtime<'18:00:00'}">
                            <a class="button border-red" href="javascript:void(0)"
                            >早退</a>
                        </c:if>
                    </td>
                    <td>
                        <div class="button-group"><a class="button border-blue" href="javascript:void(0)"
                                                     onclick="return updateUser(${userlist.userId})"><span
                                class="icon-trash-o"></span> 修改</a>
                        </div>
                    </td>
                </tr>
            </c:forEach>

            <tr>
                <td colspan="8">
                    <div class="pagelist">
                        共${userlist.totalPageNumber}页
                        <a href="${pageContext.request.contextPath}/userPage.do?currentNum=1">首页</a>
                        <a href="${pageContext.request.contextPath}/userPage.do?currentNum=${userlist.prePageNumber}">上一页</a>
                        <c:forEach var="bianhaoelement" begin="1" end="${userlist.totalPageNumber}" step="1">

                        <c:if test="${bianhaoelement >= userlist.prePageNumber && bianhaoelement <= userlist.nextPageNumber}">
                        <a href="${pageContext.request.contextPath}/userPage.do?currentNum=${bianhaoelement}">${bianhaoelement}</a>
                        </c:if>

                        </c:forEach>
                        <a href="${pageContext.request.contextPath}/userPage.do?currentNum=${userlist.nextPageNumber}">下一页</a>
                        <a href="${pageContext.request.contextPath}/userPage.do?currentNum=${userlist.totalPageNumber}">尾页</a>
                </td>
            </tr>
        </table>
    </div>
</form>
<h1 style="text-align: center;font-size: 20px;margin-top:40px">饼状图</h1>

<div id="main" style="width: 800px;height:500px;margin-left: 20%"></div>
<script>
    window.onload= function echart(){
        var userId= $("#user").val();
        var date = $("#datemonth").val();
        $.ajax({
            data:'{"userId":"'+userId+'","date":"'+date+'"}',
            contentType:"application/json;charset=UTF-8",
            type: "POST",
            dataType: 'json',
            url: "echartToAttendance.do",
            success: function (data) {
                console.log(data);
                // var attendance=JSON.stringify(data);
                // console.log(attendance);
                console.log(data.userId+"---"+data.days);

                var dom = document.getElementById("main");
                var myChart = echarts.init(dom);
                var app = {};
                var option;
                option = {
                    legend: {
                        top: 'bottom'
                    },
                    toolbox: {
                        show: true,
                        feature: {
                            mark: {show: true},
                            dataView: {show: true, readOnly: false},
                            restore: {show: true},
                            saveAsImage: {show: true}
                        }
                    },
                    series: [
                        {
                            name: '面积模式',
                            type: 'pie',
                            radius: [50, 200],
                            center: ['50%', '50%'],
                            roseType: 'area',
                            itemStyle: {
                                borderRadius: 3
                            },
                            data: [
                                { value: data.days, name: '出勤天数'+data.days },
                                { value: data.outnum, name: '早退次数'+data.outnum },
                                { value: data.latenum, name: '迟到次数'+ data.latenum }

                            ]
                        }
                    ]
                };

                if (option && typeof option === 'object') {
                    myChart.setOption(option);
                }


            },
            error: function (data) {
                alert("fail");
            }
        })
    }

</script>
<script>


</script>
</script>
<script type="text/javascript">
    function findByMonth(){
        var date = $("#month").val();
        var userId=$("#user").val();
        console.log(date);
        window.location.href="${pageContext.request.contextPath}/findUserAttendanceByUserId.do?date="+date+"&userId="+userId;
    }
    function updateStatus(userId, userStatus) {
        $.ajax({
            data: "userId=" + userId + "&userStatus=" + userStatus,
            type: "POST",
            dataType: 'json',
            url: "updateUserStatus.do",
            success: function (data) {
                location.reload();
                var input = document.getElementById(data.userId);
                if (data.userStatus == 'Y') {
                    input.setAttribute("value", "禁用");
                } else {
                    input.setAttribute("value", "启用");
                }
            },

            error: function (data) {
                alert("fail");
            }
        });
    }

    function updateUser(id) {
        if (confirm("您确定要修改" + id + "吗?")) {
            console.log(id);
            window.location.href = "${pageContext.request.contextPath}/updateUserPage.do?id=" + id;
        }
    }

    function del(id) {
        if (confirm("您确定要删除吗?")) {
            window.location.href = "${pageContext.request.contextPath}/deleteUser.do?id=" + id;
        }
    }

    $("#checkall").click(function () {
        $("input[name='id[]']").each(function () {
            if (this.checked) {
                this.checked = false;
            } else {
                this.checked = true;
            }
        });
    })

    function DelSelect() {
        var Checkbox = false;
        $("input[name='id[]']").each(function () {
            if (this.checked == true) {
                Checkbox = true;
            }
        });
        if (Checkbox) {
            var t = confirm("您确认要删除选中的内容吗？");
            if (t == false) return false;
        } else {
            alert("请选择您要删除的内容!");
            return false;
        }
    }

</script>
</body>
</html>